<?php

namespace app\company\controller;

use app\merchant\model\ExpenseRecordModel;
use app\pilot\model\BalanceRecordModel;
use think\admin\Controller;

/**
 * 支出记录管理
 * @class ExpenseRecord
 * @package app\company\controller
 */
class ExpenseRecord extends Controller
{
    /**
     * 支出记录列表
     * @auth true
     * @menu true
     */
    public function index()
    {
        $merchant = $this->app->session->get('merchant');
        if (empty($merchant)) $this->error('没有权限');
        $this->title = '任务支出记录列表';
        $this->type_dict = ExpenseRecordModel::TYPE_DICT;
        ExpenseRecordModel::mQuery()->alias('er')
            ->with(['merchant', 'task_order'])
            ->field('er.*')
            ->where('er.merchant_id', $merchant['id'])
            ->join('merchant m', 'er.merchant_id=m.id')
            ->join('task_order to', 'er.task_order_id=to.id')
            ->like('m.nickname#merchant_nickname,m.company#merchant_company')
            ->dateBetween('er.create_at#create_at')
            ->order('er.id desc')
            ->layTable();
    }

    /**
     * 列表数据处理
     * @param array $data
     */
    protected function _index_page_filter(array &$data)
    {
        foreach ($data as &$vo){
            if(isset($vo['type'])) $vo['type_text'] = ExpenseRecordModel::TYPE_DICT[$vo['type']] ?? '';
        }
    }
}
